package com.nanako.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public final class MySqlSessionFactory {
    private static InputStream in;

    static {
        try {
            in = Resources.getResourceAsStream("mybatis-config.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static SqlSession sqlSession = new SqlSessionFactoryBuilder().build(in).openSession();

    public MySqlSessionFactory() throws IOException {
    }

    public static<T> T getMapper(Class<T> resourceMapper, String config) throws IOException {
        return sqlSession.getMapper(resourceMapper);
    }
    public static void commit(){
        sqlSession.commit();
    }



}
